/**
 * Created by enixjin on 1/10/18.
 */
import {UserService} from "../../../../service/userService";
import {AbstractDataAction} from "../../AbstractDataAction";
import {AbstractUserAction} from "../AbstractUserAction";
import {AbstractUserRESTAction} from "../AbstractUserRESTAction";
import {UserListCompleteAction} from "../data";
import {UserListRESTAction} from "../rest";

export class UserListAction extends AbstractUserAction {
    listAction = true;

    constructor(private userService: UserService) {
        super();
    }

    getRestAction(): AbstractUserRESTAction {
        return new UserListRESTAction(this.userService, this.getLocalKey(), this.payload);
    }

    getDataAction(local): AbstractDataAction {
        return new UserListCompleteAction(this.loadFromLocal(local));
    }

    updateLocal(local): void {
        // do nothing for list action
    }

    loadFromLocal(local): any {
        let result = local.get(this.getLocalKey());
        if (result) {
            result = result.filter(u => !u.deleted);
        }
        return result;
    }

}
